package solitaire.presentation;

import java.awt.Point;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

import solitaire.InterfacesControle.ICTasDeCartes;
import solitaire.InterfacesPresentation.IPCarte;
import solitaire.InterfacesPresentation.IPTas;
import solitaire.InterfacesPresentation.IPTasDeCartes;
import solitaire.controle.CTasDeCartes;
import solitaire.controle.CUsine;

public class PTasDeCartes extends JPanel implements IPTasDeCartes{

	private ICTasDeCartes controleur;
	
	public static void main (String args []) {
		JFrame f = new JFrame ("Test PTas") ;
		PTasDeCartes tas = new PTasDeCartes (new CTasDeCartes("test", new CUsine()));
		//JPanel panel = new JPanel (new BorderLayout ()); 
		//panel.add (monComposant, BorderLayout.CENTER); 
		tas.add(new PCarte(1, 1));
		tas.add(new PCarte(1, 2));
		tas.add(new PCarte(1, 3));
		f.getContentPane ().add (tas) ;
		f.addWindowListener (new WindowAdapter () {
			public void windowClosing (WindowEvent e) {
				System.exit (0) ;
			}
		}) ;
		f.pack () ;
		f.setVisible (true) ;
	}
	
	public PTasDeCartes(ICTasDeCartes cTasDeCartes){
		controleur = cTasDeCartes;
		setLayout(new OverlapLayout(new Point(15, 0)));
	}
	
	@Override
	public JComponent getJComponent() {
		return this;
	}

	@Override
	public void setControleur(ICTasDeCartes cTasDeCartes) {
		controleur = cTasDeCartes;
	}

	@Override
	public void depiler() {
		// TODO Auto-generated method stub
		repaint();
		
	}

	@Override
	public void empiler(IPCarte presentation) {
		add(presentation.getJPanel());
		repaint();
		
	}
	
	@Override
	public void empiler(IPTas tas) {
		add(tas.getJComponent());
		repaint();
		
	}
	
	@Override
	public ICTasDeCartes getControleur() {
		return controleur;
	}

}
